<!DOCTYPE html>
<html lang="en" style="font-size: 20px;">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>小说模式3</title>
    <style>
        html,
        body {
            margin: 0;
            padding: 0;
            height: 100%;
        }

        iframe {
            width: 100%;
            opacity: 0;
            border: none;
        }

        h4 {
            font-size: 1rem;
        }

        .singlePage {
            font-size: 0.8rem;
            /* border-bottom: 4px solid #8b8b8d; */
            transition: all linear .4s;
        }

        .authorAndDate {
            font-size: 0.7rem;
        }

        img {
            width: 100% !important;
        }

        a {
            text-decoration: none;
        }

        .day a, body a {
            /* color: #000 !important; */
        }

        .night a {
            color: #2a779d !important;
        }

        .day, body {
            background: #f2f2f2;
        }

        .night {
            background: #222224;
            color: #8b8b8d !important;
        }

        .endTxt {
            text-align: center;
            font-size: 0.7rem;
            color: #8b8b8d;
            margin: 0.8rem 0;
        }
    </style>
</head>

<body>
<div id="novel" style="width: 100%;overflow: scroll">
    <iframe id="ramForSingleNovel" frameborder="0" style="position: fixed;left: -1000%;"></iframe>
    <div id="novelContent"></div>
    <div id="loadMore"
         style="width: 100%;height: 60px;line-height: 60px;font-size: 14px;text-align: center;margin: 0;padding: 0;">
        正在加载下一章
    </div>
</div>
<script>
    function createSinglePage(ele) { // 创建单篇容器
        var div = document.createElement('div');
        div.className = 'singlePage';
        div.style.opacity = '0';
        ele.appendChild(div);
        return div;
    }

    function shield(data) { // 屏蔽数据中的 Iframe, Script, Css, Style
        var iframeReg = /<iframe(.|\r|\n)*?>(.|\r|\n)*?<\/iframe>{1}/g;
        var scriptReg = /<script(.|\r|\n)*?>(.|\r|\n)*?<\/script>{1}/g;
        var cssReg = /<link(.|\r|\n)*?>{1}/g;
        var styleReg = /<style(.|\r|\n)*?>(.|\r|\n)*?<\/style>{1}/g;
        var evalReg = /\"eval([^\"]*?)\"/g;
        // var aReg =/<a([\s]+|[\s]+[^<>]+[\s]+)href=(\"([^<>"\']*)\"|\'([^<>"\']*)\')[^<>]*>/g;
        // return data.replace(iframeReg, '').replace(scriptReg, '').replace(cssReg, '').replace(styleReg, '').replace(aReg, '');
        return data.replace(iframeReg, '').replace(scriptReg, '').replace(cssReg, '').replace(styleReg, '').replace(evalReg, '');
        ;
    }

    function getHost() {
        return FuTillIFu.getHost();
    }

    var novel = document.getElementById('novel');
    var content = document.getElementById('novelContent');
    var ram = document.getElementById('ramForSingleNovel');
    var loading = document.getElementById('loadMore');

    function setNovel(data) { // 插入小说内容
        var div = createSinglePage(content);
        div.innerHTML = data;
        var endTxt = document.createElement('div');
        endTxt.innerHTML = '······本章完······';
        endTxt.className = 'endTxt';
        div.appendChild(endTxt);
        div.style.opacity = '1';
    }

    function start(data) { // 启动
        //var content = shield(data);
        content = data;
        var doc = ram.contentDocument || ram.document;
        doc.documentElement.innerHTML = content; // 缓存单篇小说内容
        var script = document.createElement('script');
        script.src = './xser.js';
        doc.documentElement.appendChild(script);
    }

    function setFontSize(num) { // 设置字体大小
        document.getElementsByTagName('html')[0].style.fontSize = num * 20 + 'px';
    }

    function modeToggle(mode) { // 切换夜间/正常模式
        var body = document.body || document.documentElement;
        if (mode == 'night') {
            body.className = 'night';
        } else if (mode == 'day') {
            body.className = 'day';
        }
    }

    function loadErr() { // 重试加载
        function loadHandler() {
            loading.innerText = '正在加载...';
            FuTillIFu.onLoadMore();
            loading.removeEventListener('click', loadHandler, false);
        }

        loading.innerText = '加载失败, 点击重试';
        loading.addEventListener('click', loadHandler, false);
    }

    //文档高度
    function getDocumentTop() {
        var scrollTop = 0,
            bodyScrollTop = 0,
            documentScrollTop = 0;
        if (document.body) {
            bodyScrollTop = document.body.scrollTop;
        }
        if (document.documentElement) {
            documentScrollTop = document.documentElement.scrollTop;
        }
        scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop;
        return scrollTop;
    }

    //可视窗口高度
    function getWindowHeight() {
        var windowHeight = 0;
        if (document.compatMode == "CSS1Compat") {
            windowHeight = document.documentElement.clientHeight;
        } else {
            windowHeight = document.body.clientHeight;
        }
        return windowHeight;
    }

    //滚动条滚动高度
    function getScrollHeight() {
        var scrollHeight = 0,
            bodyScrollHeight = 0,
            documentScrollHeight = 0;
        if (document.body) {
            bodyScrollHeight = document.body.scrollHeight;
        }
        if (document.documentElement) {
            documentScrollHeight = document.documentElement.scrollHeight;
        }
        scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight;
        return scrollHeight;
    }

    var isLoading = false;

    function loaded() {
        isLoading = false;
    }

    function refresh() {// 目錄內容切換
        window.removeEventListener('scroll', scrollHandler, false);
        novel.style.opacity = '0';
        content.innerHTML = '';
        novel.style.opacity = '1';
    }

    function scrollHandler() {
        //if ((getScrollHeight() - getWindowHeight() - getDocumentTop()) < 30) {
        //    if (!isLoading) {
        //        FuTillIFu.onLoadMore();
        //        isLoading = true;
        //    }
        //}
        if (getScrollHeight() > 30) {
            if (!isLoading) {
                FuTillIFu.onLoadMore();
                isLoading = true;
            }
        }
    }

    gg

    function action() {
        start(FuTillIFu.getDom());
        window.addEventListener('scroll', scrollHandler, false);
    }

</script>
</body>

</html>